package com.jackrain.nea.fc.pos.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wuwenxue
 * @date 2018/05/22
 **/
@Mapper
public interface ViewDLRetailPriceToF4Mapper {

    @SelectProvider(type = ViewDLRetailPriceSql.class, method = "findRetailPriceItemData")
    List<HashMap> selRetailPriceItemData(@Param("id") Object[] id);

    @Select("SELECT TYPE FROM DL_F_RETAIL_PRICE WHERE ID=#{id} AND STATUS=2")
    String selRetailPriceDate(Long id);

    class ViewDLRetailPriceSql {

        public String findRetailPriceItemData(Map<String, Object> map) {
            Object[] id = (Object[]) map.get("id");
            return new SQL() {
                {
                    SELECT("CP_C_STORE_ECODE,PS_C_PRO_ECODE,PRICE_LIST,PRICE_RETAIL,CREATIONDATE," +
                            "REMARK,MODIFIERNAME,MODIFIERENAME,MODIFIEDDATE");
                    FROM("DL_F_RETAIL_PRICE_PRO_ITEM");
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < id.length; i++) {
                        sb.append(id[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("DL_F_RETAIL_PRICE_ID IN (" + sb.toString() + ")");
                }
            }.toString();
        }
    }


}
